package community.hospital.service.domain.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import community.hospital.common.BasePage;
import community.hospital.entity.Hospital;
import community.hospital.entity.request.ListHospitalRequest;
import community.hospital.service.domain.HospitalService;
import community.hospital.mapper.HospitalMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import static community.hospital.common.Constant.STATE_ENABLE;

/**
* @author ydj
* @description 针对表【hospital(医院信息表)】的数据库操作Service实现
* @createDate 2023-01-27 15:05:08
*/
@Service
public class HospitalServiceImpl extends ServiceImpl<HospitalMapper, Hospital>
    implements HospitalService{
    @Resource
    private HospitalMapper hospitalMapper;
    @Override
    public Page<Hospital> listHospital(ListHospitalRequest request) {
        Page<Hospital> page = new Page<>(request.getPageNumber(), request.getPageSize());
        lambdaQuery()
                .eq(request.getState()!=null,Hospital::getState,request.getState())
                .eq(StringUtils.isNotBlank(request.getName()),Hospital::getName,request.getName())
                .eq(StringUtils.isNotBlank(request.getLevel()),Hospital::getLevel,request.getLevel())
                .page(page);
        return page;
    }

    @Override
    public int countByCreditCode(String creditCode) {
        return lambdaQuery().eq(Hospital::getCreditCode, creditCode).count().intValue();

    }

    @Override
    public int countByName(String name) {
        return lambdaQuery().eq(Hospital::getName,name).count().intValue();
    }

    @Override
    public List<Hospital> listOptionHospital() {
        return lambdaQuery().eq(Hospital::getState, STATE_ENABLE).list();
    }


}




